
package ejemplodeawt;
import java.awt.*;
import java.awt.event.*;

public class Agregar {
    private TextArea ta;
    private TextField tf;
    private Button b;
    private Button b2;
    private Menu m;
    private MenuBar mb;
    private MenuItem mi;
    private MenuItem mi1;
public void ventana(){
    Frame f=new Frame();
    Panel p=new Panel();
    p.setLayout(new GridLayout(4,1));
    ta=new TextArea();
    tf=new TextField();
    b=new Button("Agregar");
    b2=new Button("Reset");
    b.addActionListener(new manejoBoton());
    b.addMouseListener(new cambiocolor());
    b2.addActionListener(new manejoBoton2());
    tf.addKeyListener(new enter());
    m= new Menu("Menu");
    mb=new MenuBar();
    mi=new MenuItem("nuevo");
    mi.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e) {
                ta.setText(" ");
                tf.setText(" ");
            }
    });
    mi1=new MenuItem("salir");
    mi1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
               System.exit(0);
            }
    });
    m.add(mi);
    m.add(mi1);

    mb.add(m);
    f.setMenuBar(mb);
    p.add(ta);
    p.add(tf);
    p.add(b);
    p.add(b2);
    f.add(p);
    f.setBounds(50, 50, 500, 500);
    f.setVisible(true);

    f.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent ev){
        System.exit(0);
    }
    });
}
class manejoBoton implements ActionListener{
public void actionPerformed(ActionEvent ev){
     ta.append("\n"+tf.getText());
    }
  }
class manejoBoton2 implements ActionListener{
        public void actionPerformed(ActionEvent e) {
ta.setText(" ");
tf.setText(" ");
        }

  }
class enter extends KeyAdapter{
    public void keyPressed(KeyEvent ev){
       if(ev.getKeyCode()==10){
            ta.append("\n"+tf.getText());
       }
    }
}
class cambiocolor extends MouseAdapter{
        public void mouseEntered(MouseEvent e) {
            b.setBackground(Color.green);
        }
        public void mouseExited(MouseEvent e) {
            b.setBackground(Color.red);
        }
}
public static void main(String args []){
    Agregar v=new Agregar();
    v.ventana();
}
}
